define(['app', 'assets/js/bootstrap.bundle.min.js', 'assets/js/bootstrap-select.js'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {

	$scope.form = {};

	$scope.rollback = function (){
		$scope.upgrade('1');
	}

	$scope.affirm = function() {
		let old_fk_grades = '';
		let arrayIds = $('#my_select').val();
		arrayIds.forEach((item,index,arr)=> {
			old_fk_grades = old_fk_grades+",'"+item+"'";
		})
		if (arrayIds.length > 0){
			eventBusService.publish("modal.alert",{"content":"是否确认？","isAutoClose":false,"confirm":function(){
					httpService.post(app.urls.batchConfirmEnrollment, {'old_fk_grades':old_fk_grades.replace(',','')}, function (data) {
						if (data.code == "0000") {
							eventBusService.publish("content.page.reload", data);
							eventBusService.publish("modal.page.close", {});
						} else {
							eventBusService.publish("modal.alert", {"content": data.msg});
						}
					});
				},"cancel":function(){
					//用户取消，不做操作
				}});
		}else{
			eventBusService.publish("modal.alert", {"content": "请选择年级。"});
		}
	}

	$scope.upgrade = function(isRollBack) {
		let old_fk_grades = '';
		let arrayIds = $('#my_select').val();
		arrayIds.forEach((item,index,arr)=> {
			old_fk_grades = old_fk_grades+",'"+item+"'";
		})
		if (arrayIds.length > 0){
			let txt = isRollBack == '0' ? '确认' : '回滚';
			eventBusService.publish("modal.alert",{"content":"是否"+txt+"？","isAutoClose":false,"confirm":function(){
				httpService.post(app.urls.batchChangeState, {'is_affirm': '1', 'old_fk_grades':old_fk_grades.replace(',','')}, function (data) {
					if (data.code == "0000") {
						httpService.post(app.urls.updateUpgradeState, {'is_roll_back': isRollBack, 'old_fk_grades':old_fk_grades.replace(',','')}, function (data) {});
						eventBusService.publish("content.page.reload", data);
						eventBusService.publish("modal.page.close", {});
					} else {
						eventBusService.publish("modal.alert", {"content": data.msg});
					}
				});
			},"cancel":function(){
				//用户取消，不做操作
			}});
		}else{
			eventBusService.publish("modal.alert", {"content": "请选择年级。"});
		}
	}

	$scope.getGradeList = function (){
		httpService.post(app.urls.getUpdateGradeList, $scope.form, function(data) {
			if("0000" === data.code) {
				$scope.gradeList = data.data;
			}
		});
	}

	//学生状态
	$scope.findStudentStatus = function(){
		httpService.post(app.urls.dictionary_selectByRule,{fk_rule:"SJAAAAA10061", name: '毕业'},function(data){
			if("0000" === data.code){
				console.log(data.data[0].id);
			}else{
				alert(data.msg);
			}
		});
	}

	let init = function () {
		$scope.getGradeList();
		$scope.findStudentStatus();
		setTimeout(function (){
			$('#my_select').selectpicker({
				'noneSelectedText': '==请选择年级==',
				'selectAllText': '选择全部',
				'deselectAllText': '取消全选',
			});
		}, 500);
	}

	init();

}}});